function arrowClick(event) {
	let list = event.currentTarget.parentElement.getElementsByClassName("dropdown-list")[0];

	if (list.style.display == "none") {
		list.style.display = "block";
	} else {
		list.style.display = "none";
	}
}

function itemClick(event) {
	let list = event.currentTarget.parentElement.parentElement;
	let input = list.parentElement.children[0];
	input.value = this.innerHTML;
	
	if (list.style.display == "none") {
		list.style.display = "block";
	} else {
		list.style.display = "none";
	}
}

function outsideClick(event) {
	let inputs = document.getElementsByClassName("dropdown-input");

    for (i = 0; i <= inputs.length - 1; i++) {
        if (inputs[i].contains(event.target) == false) {
            inputs[i].getElementsByClassName("dropdown-list")[0].style.display = "none";
        }
    }
}

window.onload = function() {
	let arrows = document.getElementsByClassName("dropdown-arrow");

	for (i = 0; i <= arrows.length - 1; i++) {
		arrows[i].addEventListener("click", arrowClick);
	}
	
	let lists = document.getElementsByClassName("dropdown-list");

	for (j = 0; j <= lists.length - 1; j++) {
		let orderedList = lists[j].children[0];
		
		for (k = 0; k <= orderedList.childElementCount - 1; k++) {
			orderedList.children[k].addEventListener("click", itemClick);
		}
	}

	document.addEventListener("click", outsideClick);
}